﻿using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
using static System.Runtime.InteropServices.JavaScript.JSType;

namespace WpfApp1Calculator;

/// <summary>
/// Interaction logic for MainWindow.xaml
/// </summary>
public partial class MainWindow : Window
{
    public MainWindow()
    {
        InitializeComponent();
    }

    double value = .0;
    int number = 0;
    int number1 = 0;
    int number2 = 0;
    string symbol = string.Empty;
    private void buttonEqual_Click(object sender, RoutedEventArgs e)
    {
        e.Handled = true;
    }

    private void Grid_Click(object sender, RoutedEventArgs e)
    {
        int digit;
        string content = ((Button)e.Source).Content.ToString();
        if (int.TryParse(content, out digit))
        {
            number = number * 10 + digit;
            textBlock.Text = number.ToString();
        }

        if(content == "+")
        {
            if (number1>0 & number2 > 0)
            {
                textBlock.Text = (number1 + number2).ToString();
            }
            else if (number1 > 0)
            {

            }
            else
            {
                number1 = number;
            }
        }
        else if (content == "-")
        {
            if (number1 > 0 & number2 > 0)
            {
                textBlock.Text = (number1 - number2).ToString();
            }
            else if (number1 > 0)
            {

            }
            else
            {
                number1 = number;
            }
        }
        else if (content == "X")
        {
            if (number1 > 0 & number2 > 0)
            {
                textBlock.Text = (number1 * number2).ToString();
            }
            else if (number1 > 0)
            {

            }
            else
            {
                number1 = number;
            }
        }
        else if (content == "/")
        {
            if (number1 > 0 & number2 > 0)
            {
                textBlock.Text = (number1 / number2).ToString();
            }
            else if (number1 > 0)
            {

            }
            else
            {
                number1 = number;
            }
        }
        else if (content == "=")
        {
            textBlock.Text = value.ToString();
            value = .0;
        }
    }
}